#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
using namespace std;
#include <vector>
int main()
{
    vector<char> dp;
    int n;
    cin >> n;
    string s;
    cin >> s;
    dp.push_back(s[0]);
    for (int i = 1; i < n; i++)
    {
        if (s[i] >= dp[dp.size() - 1])
        {
            dp.push_back(s[i]);
            continue;
        }
        int left = 0, right = dp.size() - 1;
        while (left < right)
        {
            int mid = (left + right - 1) / 2;
            if (s[i] < dp[mid])
                right = mid;
            else
                left = mid + 1;
        }
        //         if(s[i]>dp[left]) dp[left-1] = s[i];
        //         else dp[left] = s[i];
        dp[left] = s[i];
    }
    for (auto& e : dp)
        cout << e;
    cout << endl;
    cout << n - dp.size() << endl;
    return 0;
}